﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace KeywordAuction
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            initializeAdspot();
        }
        public Adspot Adspot { get; set; }
     
        private void initializeAdspot()
        {
            Adspot adspot = new Adspot();

            Random rondom = new Random();
            List<double> clickThroughtRates = new List<double>();
            for (int i = 0; i < 10; i++)
            {
                double value = (double)rondom.Next(10000);
                clickThroughtRates.Add(value / 10000);

            }
            adspot.ClickThroughtRates = clickThroughtRates;

            for (int i = 0; i < 100; i++)
            {
                adspot.ClickThroughtRates.Add(0);
            }
            adspot.ClickThroughtRates = adspot.ClickThroughtRates;

            List<AdvertiserBidding> advertisers = new List<AdvertiserBidding>();
            for (int i = 0; i < 100; i++)
            {
                //var advertiser = new AdvertiserBidding();
                //advertiser.ExpectedRevenue = rondom.Next(100);
                //advertiser.Bid = advertiser.ExpectedRevenue;
                //advertisers.Add(advertiser);
            }
            adspot.Bitting = advertisers;
            Adspot = adspot;
        }
        private void buttonGSP_Click(object sender, EventArgs e)
        {
            this.textBox2.Text = "";
            this.textBox1.Text = "";
            this.listBoxResult.Items.Clear();
            for (int iBase = 0; iBase < 50; iBase++)
            {
                initializeAdspot();
                for (int i = 0; i < 10; i++)
                {
                    //double result = Adspot.GetPaymentValueForGSP(i);
                    //var bitter = Adspot.Bitters[i];
                    //var rate = Adspot.ClickThroughtRates[i];
                    //if (rate != 0)
                    //{
                    //    this.textBox1.Text += (((bitter.ExpectedRevenue * rate) - result)* 1000).ToString() + Environment.NewLine;
                    //    this.textBox2.Text += bitter.ExpectedRevenue + Environment.NewLine;

                    //}
                  //  this.listBoxResult.Items.Add(string.Format("revenue:{0}, pay:{1} ,bit:{2}, exRev:{3} rate:{4}", (bitter.ExpectedRevenue * rate) - result, result, bitter.Bid, bitter.ExpectedRevenue, rate));
                }               
            }
 
        }

        private void buttonClear_Click(object sender, EventArgs e)
        {

            this.textBox1.Text = "";
            this.textBox2.Text = "";
            this.listBoxResult.Items.Clear();
        }

        private void buttonRun_Click(object sender, EventArgs e)
        {

            this.textBox2.Text = "";
            this.textBox1.Text = "";
            this.listBoxResult.Items.Clear();
            for (int iBase = 0; iBase < 50; iBase++)
            {
                initializeAdspot();
                for (int i = 0; i < 10; i++)
                {
                    //double result = Adspot.GetPaymentValueForVCG(i);
                    //var bitter = Adspot.Bitters[i];
                    //var rate = Adspot.ClickThroughtRates[i];
                    //if (rate != 0)
                    //{
                    //    this.textBox1.Text += (((bitter.ExpectedRevenue * rate) - result) * 1000).ToString() + Environment.NewLine;
                    //    this.textBox2.Text += bitter.ExpectedRevenue + Environment.NewLine;
                    //}
                    //  this.listBoxResult.Items.Add(string.Format("revenue:{0}, pay:{1} ,bit:{2}, exRev:{3} rate:{4}", (bitter.ExpectedRevenue * rate) - result, result, bitter.Bid, bitter.ExpectedRevenue, rate));
                }
            }



            //for (int i = 0; i < 20; i++)
            //{
            //    double result = Adspot.GetPaymentValueForVCG(i);
            //    var bitter = Adspot.Bitters[i];
            //    var rate = Adspot.ClickThroughtRates[i];

            //    this.listBoxResult.Items.Add(string.Format("revenue:{0}, pay:{1} ,bit:{2}, exRev:{3} , rate:{4}",( bitter.ExpectedRevenue * rate) - result, result, bitter.Bid, bitter.ExpectedRevenue,rate));
            //    double resultRev = bitter.ExpectedRevenue * rate;
            //    if (resultRev - result == 0)
            //    { 

            //    }
            //}
        }

        private void buttonReset_Click(object sender, EventArgs e)
        {
            initializeAdspot();
        }
    }
}
